<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2019-11-12
 * Time: 20:13
 */

namespace app\api\service;
use app\api\model\HotelRoomOrder;
use app\api\model\MemberOrder;
use app\api\model\ProjectHatchCommentOrder;
use app\api\model\ProjectHatchLookOrder;
use app\api\model\ProjectHatchOrder;
use app\api\service\order\HatchCommentSer;
use app\api\service\order\HatchLookSer;
use app\api\service\order\HatchSer;
use app\api\service\order\HotelRoomSer;
use app\api\service\order\MemberSer;



class WxNotify extends \WxPayNotify
{
    public function NotifyProcess($objData, $config, &$msg)
    {
       if($objData['result_code'] == 'SUCCESS')
        {

            $outTradeNo = $objData['out_trade_no'];
            //获取通知的数据
            if (empty($outTradeNo)) {
                # 如果没有数据，直接返回失败
                return false;
            }
            /**
             * 根据订单类型进行操作
             */
            $outTradeNoArr = explode("y",$outTradeNo);
            $type = $outTradeNoArr[0];
            return $this->updateOrder($type,$outTradeNo);
        }
        else{
            return true;
        }
    }

    /**
     * 查询订单信息
     * 获取公用修改方法
     */
    private function updateOrder($type,$outTradeNo)
    {
        if($type == 1) {
            $order = MemberOrder::where('out_trade_no',$outTradeNo)->find();
            $memberSer = new MemberSer($order);
            $memberSer->changeStatus();
        } elseif($type == 2) {
            $order = HotelRoomOrder::where('out_trade_no',$outTradeNo)->find();
            $hotelRoomSer = new HotelRoomSer($order);
            $hotelRoomSer->changeStatus();
        } elseif($type == 3){
            $order = ProjectHatchOrder::where('out_trade_no',$outTradeNo)->find();
            $hatchSer = new HatchSer($order);
            $hatchSer->changeStatus();
        } elseif($type == 4){
            $order = ProjectHatchCommentOrder::where('out_trade_no',$outTradeNo)->find();
            $hatchCommentSer = new HatchCommentSer($order);
            $hatchCommentSer->changeStatus();
        } elseif($type == 5){
            $order = ProjectHatchLookOrder::where('out_trade_no',$outTradeNo)->find();
            $HatchLookSer = new HatchLookSer($order);
            $HatchLookSer->changeStatus();
        }
    }
}